package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.QtUsesrCourseMapper;
import com.ruoyi.system.domain.QtUsesrCourse;
import com.ruoyi.system.service.IQtUsesrCourseService;
import org.springframework.transaction.annotation.Transactional;

/**
 * userCourseService业务层处理
 * 
 * @author ruoyi
 * @date 2021-11-26
 */
@Service
public class QtUsesrCourseServiceImpl implements IQtUsesrCourseService 
{
    @Autowired
    private QtUsesrCourseMapper qtUsesrCourseMapper;

    /**
     * 查询userCourse
     * 
     * @param id userCourse主键
     * @return userCourse
     */
    @Override
    public QtUsesrCourse selectQtUsesrCourseById(Integer id)
    {
        return qtUsesrCourseMapper.selectQtUsesrCourseById(id);
    }

    /**
     * 查询userCourse列表
     * 
     * @param qtUsesrCourse userCourse
     * @return userCourse
     */
    @Override
    public List<QtUsesrCourse> selectQtUsesrCourseList(QtUsesrCourse qtUsesrCourse)
    {
        return qtUsesrCourseMapper.selectQtUsesrCourseList(qtUsesrCourse);
    }

    /**
     * 新增userCourse
     * 
     * @param qtUsesrCourse userCourse
     * @return 结果
     */
    @Override
    public int insertQtUsesrCourse(QtUsesrCourse qtUsesrCourse)
    {
        return qtUsesrCourseMapper.insertQtUsesrCourse(qtUsesrCourse);
    }

    /**
     * 修改userCourse
     * 
     * @param qtUsesrCourse userCourse
     * @return 结果
     */
    @Override
    public int updateQtUsesrCourse(QtUsesrCourse qtUsesrCourse)
    {
        return qtUsesrCourseMapper.updateQtUsesrCourse(qtUsesrCourse);
    }

    /**
     * 批量删除userCourse
     * 
     * @param ids 需要删除的userCourse主键
     * @return 结果
     */
    @Override
    public int deleteQtUsesrCourseByIds(Integer[] ids)
    {
        return qtUsesrCourseMapper.deleteQtUsesrCourseByIds(ids);
    }

    /**
     * 删除userCourse信息
     * 
     * @param id userCourse主键
     * @return 结果
     */
    @Override
    public int deleteQtUsesrCourseById(Integer id)
    {
        return qtUsesrCourseMapper.deleteQtUsesrCourseById(id);
    }
    /**
     * 批量添加
     * @param qtUsesrCourse
     * @return
     */
    @Transactional
    public int batchinster(QtUsesrCourse qtUsesrCourse){
        try {
            String[] ids=qtUsesrCourse.getUserId().split(",");
            qtUsesrCourse.setIsNow(1);
            for (String item:ids) {
                qtUsesrCourse.setUserId(item);

                qtUsesrCourseMapper.insertQtUsesrCourse(qtUsesrCourse);
            }
            return 1;
        }catch (Exception e) {
            return 0;
        }
    }
}
